/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testadventure;

import edu.clemson.cs.hamptos.adventure.AdventureCommand;
import edu.clemson.cs.hamptos.adventure.AdventureEngine;
import edu.clemson.cs.hamptos.adventure.AdventureTarget;
import edu.clemson.cs.hamptos.adventure.AdventureWindow;
import edu.clemson.cs.hamptos.adventure.VerbStrategyAlt;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

/**
 *<p>Implements the <code>VerbStrategyAlt</code> interface.</p>
 * 
 */
public class VerbOpenDrawer implements VerbStrategyAlt {
    protected final HashSet<String> verbs = new HashSet<String>();
    /**
     * <p>Constructs a new instance of <code>VerbOpenDrawer</code> object.
     * 
     */
    VerbOpenDrawer()
    {
        verbs.add("open");
        verbs.add("unlock");
    }

    @Override
    public void doCommand(AdventureCommand c, AdventureEngine e, AdventureWindow w) {
        AdventureTarget thedo = c.getDirectObject();
        AdventureTarget theio = c.getIndirectObject();
        
        
        HashMap<String, Integer> dostats = thedo.getStats();
        HashMap<String, Integer> idostats = theio.getStats();
        
        //see if do is defeated or still active
        if (dostats.get("enabled") == 0)
        {
            w.println(thedo.getShortDescription() + " is already open.");
            return;
        }
        
        w.println("You opened " + thedo.getShortDescription());
        
        dostats.put("enabled", 0);
        idostats.put("charges", 0);
        
        try
        {
            e.removeFromPlayerInventory(theio);
            e.getPlayerLocation().removeLocalTarget(theio);
        }
        catch (IllegalStateException ex)
        {
            e.getPlayerLocation().removeLocalTarget(theio);
        }
    } 
        @Override
    public String getName() {
        return "VerbOpenDrawer";
    }

    @Override
    public Set<String> getVerbs() {
        return new HashSet<String>(verbs);
    }
    
}
